package com.flyduck.vueshop.user.h5.controller;

import com.flyduck.vueshop.common.core.lang.Result;
import com.flyduck.vueshop.common.sotoken.annotation.Login;
import com.flyduck.vueshop.user.h5.service.H5AddressService;
import com.flyduck.vueshop.user.h5.vo.H5AddressDetailsRespVO;
import com.flyduck.vueshop.user.h5.vo.H5AddressRespVO;
import com.flyduck.vueshop.user.h5.vo.H5AddressSaveReqVO;
import com.flyduck.vueshop.user.h5.vo.H5AddressUpdateReqVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * AppAddressController
 * </p>
 *
 * @author flyduck
 * @since 2024-06-19
 */
@RestController
@RequestMapping("/user/h5/address")
public class H5AddressController {

    @Resource
    private H5AddressService h5AddressService;

    @Login
    @GetMapping("/getAddressList")
    public Result<List<H5AddressRespVO>> getAddressList(){
        List<H5AddressRespVO> addressRespVOList = h5AddressService.getAddressList();
        return Result.success(addressRespVOList);
    }

    @Login
    @GetMapping("/getAddressDetailsById/{id}")
    public Result<H5AddressDetailsRespVO> getAddressDetailsById(@PathVariable("id") Long id){
        H5AddressDetailsRespVO h5AddressDetailsRespVO = h5AddressService.getAddressDetailsById(id);
        return Result.success(h5AddressDetailsRespVO);
    }

    @Login
    @PostMapping("/saveAddress")
    public Result<Void> saveAddress(@Validated @RequestBody H5AddressSaveReqVO h5AddressSaveReqVO){
        h5AddressService.saveAddress(h5AddressSaveReqVO);
        return Result.success();
    }

    @Login
    @PostMapping("/updateAddress")
    public Result<Void> updateAddress(@Validated @RequestBody H5AddressUpdateReqVO h5AddressUpdateReqVO){
        h5AddressService.updateAddress(h5AddressUpdateReqVO);
        return Result.success();
    }

    @Login
    @PostMapping("/deleteById/{id}")
    public Result<Void> deleteById(@PathVariable("id") Long id){
        h5AddressService.deleteById(id);
        return Result.success();
    }

}
